package org.xiji.Prototype;

import java.io.*;

/**
 *
 */
public class Student implements Serializable, Cloneable {
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    /**
     * 通过创建对象克隆对象
     */

    @Override
    public Student clone() {

        return new Student(this.name,this.age);

    }

    /**
     * 通过java字节流流克隆对象
     */

    public Student cloneByStream() {
        try {

            ByteArrayOutputStream outPutStream = new ByteArrayOutputStream();

            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outPutStream);

            objectOutputStream.writeObject(this);


            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(outPutStream.toByteArray());


            ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);


            return (Student) objectInputStream.readObject();


        } catch (Exception e) {
            e.printStackTrace();

        }



        return null;
    }









}
